#pragma once 

#include <memory>
#include <optional>
#include "helper/sqlite/stream/Iterator.h"

#include "helper/sqlite/stream/Row.h"
#include "helper/sqlite/stream/Room.h"


namespace helper {
namespace sqlite {

  class QueryResult;

}//namespace sqlite
}//namespace helper

namespace helper {
namespace sqlite {
namespace stream {

class Row;
class Room;

class Vector {
public:
  Vector(QueryResult & r);
  ~Vector();

  class RowIterator : public Iterator<Row*> {
  public:
    typedef Row * Item;

    RowIterator(QueryResult & r);
    ~RowIterator()  override;

    std::optional<Item> next() override;
  private:
    QueryResult & _result;
    Item _row;
    int _index;
  };

  inline std::unique_ptr<Iterator<Row*>> rows() const{
    return std::make_unique<Vector::RowIterator>(_result);
  }

  class RoomIterator : public Iterator<Room*>{
  public:
    typedef Room * Item;
    RoomIterator(QueryResult & r);
    ~RoomIterator() override;

    std::optional<Item> next() override ;

  private:
    QueryResult & _result;
    size_t _rowid;
    size_t _colid;
    size_t _max_col_len;
    Item  _room;
  };

  inline std::unique_ptr<Iterator<Room*>> rooms() const{
    return std::make_unique<Vector::RoomIterator>(_result);
  }

private:
  QueryResult & _result;
};

}//namespace stream
}//namespace sqlite
}//namespace helper
